#!/bin/sh

# Copyright © 2013 Alex Kost

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

#### HELP MESSAGE ##############################################
hlp='Usage: mute
Toggle the sound on or off (mute/unmute).'

if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
    echo "$hlp"
    exit 0
fi
################################################################

## PulseAudio
# amixer get Master | grep -o '\[off\]' > /dev/null
# # if exit status after grep is 0/1 then the sound is off/on
# pactl set-sink-mute 0 $(echo $?)

## Alsa
STATE=$(amixer get Master | grep -o '\[o.*\]' | sed -n 1p)
if [ $STATE == '[on]' ]; then
    amixer -q set Master mute
else
    for ELEMENT in Master Headphone PCM
    do
	amixer -q set $ELEMENT unmute
    done &>/dev/null
fi
